﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PES_TurnierManager
{
    

    /// <summary>
    /// Interaktionslogik für TableRowControl.xaml
    /// </summary>
    public partial class TableRowControl : UserControl
    {
        public delegate void RemovedPlayerEvent(string playerName);

        public event RemovedPlayerEvent RamovedPlayer;

        private uint mCurrentRank;
        private RemovePlayerButton mRemovePlayerButton;

        public TableRowControl(string playerName, uint currentRank)
        {
            InitializeComponent();
            mPlayerNameBlock.Text = playerName;
            mPlusGoalsBlock.Text = "0";
            mMinusGoalsBlock.Text = "0";
            mGamesBlock.Text = "0";
            mPointsBlock.Text = "0";

            mCurrentRank = currentRank;
            mRemovePlayerButton = new RemovePlayerButton(playerName);
            Grid.SetColumn(mRemovePlayerButton, 6);
            mGrid.Children.Add(mRemovePlayerButton);
            mRemovePlayerButton.Click += new RoutedEventHandler(mRemovePlayerButton_Click);


            //[TODO] Add an image
        }

        /// <summary>
        /// Reacts if the player wants to remove a player from
        /// the group and passes event to external listeners.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mRemovePlayerButton_Click(object sender, RoutedEventArgs e)
        {
            if (RamovedPlayer != null)
                RamovedPlayer(getPlayerName());
        }

        public void setCurrentRank(uint rank)
        {
            mCurrentRank = rank;
        }

        public string getPlayerName()
        {
            return mPlayerNameBlock.Text;
        }

        public Button getRemoveButton()
        {
            return mRemovePlayerButton;
        }

        public uint getCurrentRank()
        {
            return mCurrentRank;
        }

        public void setPoints(string points)
        {
            mPointsBlock.Text = points;
        }

        public void setPlusGoals(string plusGoals)
        {
            mPlusGoalsBlock.Text = plusGoals;
        }

        public void setMinusGoals(string minusGoals)
        {
            mMinusGoalsBlock.Text = minusGoals;
        }

        public void setGamesPlayed(string gamesPlayed)
        {
            mGamesBlock.Text = gamesPlayed;
        }
    }
}
